/*
 * $Id$
 */

package corejs.parser;

import corejs.stmt.Statement;
import corejs.stmt.While;

import corejs.expr.Expression;

import static corejs.JsTokenType.*;

/**
 *
 * @author pengyu
 */
public class WhileParser implements StatementParser {

   @Override
   public Statement statement(final PrattParser parser) {
      parser.nextToken(LEFT_PAREN);
      final Expression test = parser.expr();
      parser.nextToken(RIGHT_PAREN);

      final Statement stmt = (parser.match(LEFT_BRACE)) 
              ? parser.block(RIGHT_BRACE) : parser.statement();

      return new While(test, stmt);
   }
   
}
